#include <my_header.h>


char* splitCommand(char* commandStr, int *commandInt){
    //
    //定义字符数组存储命令
    // char* commandStrArry[7] = {
    //     "cd", "ls", "pwd", "mkdir", "rm", "puts", "gets"
    // };
    if(strcmp(commandStr, "\n") == 0){
        *commandInt = -1;
        return NULL;
    }
    char *commandStr1 = commandStr;
    char *path1 = strtok(commandStr1, "\n");
    if(strcmp(path1, "ls") == 0){
        *commandInt = 2;
        return commandStr;
    }
    if(strcmp(path1, "pwd") == 0){
        *commandInt = 3;
        return commandStr;
    }
    char *p = strtok(commandStr, " ");//按照空格分割出命令
    char *path2 = strtok(NULL, " ");//分割中间的多个空格
    //char *path2 = strtok(NULL, "e");//分割中间的多个空格  
    //printf("path2--%s\n", path2);
    char *path = strtok(path2, "\n");//分割出path
    //printf("path--%s \n", path);
    if(strcmp(p, "cd") == 0){//cd 指令
        *commandInt = 1;
    }
    else if(strcmp(p, "mkdir") == 0){//mkdir 指令                                                                                                  
        *commandInt = 4;
    }
    else if(strcmp(p, "rm") == 0){//rm 指令                                                                                        
        *commandInt = 5;
    }
    else if(strcmp(p, "puts") == 0){//puts 指令  
        *commandInt = 6;
    }
    else if(strcmp(p, "gets") == 0){//gets 指令  
        *commandInt = 7;
    }
    else{
        //错误判断
        *commandInt = -1;
        printf("命令输入错误 \n");
    }

    // printf("* commandInt %d \n", *commandInt);
    //进行命令对比如果命令存在不做处理
    //
    //如果命令错误进行输出提示

    return path;
}

/*
int main(int argc, char *argv[])
{                                  
   char commandStr[] = "\n";
   int commandInt = -1;
   char* str =  splitCommand(commandStr, &commandInt);
    printf("改变后的命令内容：-%s- \n", str);
    printf("改变后的命令指令：%d \n", commandInt);
    return 0;
}
*/
